package com.campus.customer.controller;

import com.campus.common.bean.common.Pagination;
import com.campus.common.bean.common.Resp;
import com.campus.customer.bean.merchant.MerchantQueryParam;
import com.campus.customer.service.MerchantService;
import com.campus.customer.vo.MerchantVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 商户表 前端控制器
 * </p>
 *
 * @author ZhaoYuJie
 * @since 2025-04-02
 */
@Api(tags = "商户管理")
@RestController
@RequestMapping("/merchant")
public class MerchantController {
    @Autowired
    private MerchantService merchantService;

    @ApiOperation("分页查询商户列表")
    @GetMapping("/page")
    public Resp<Pagination<MerchantVo>> page(MerchantQueryParam param) {
        PageInfo<MerchantVo> pageInfo = merchantService.getMerchantPage(param);
        return Resp.successPageable(pageInfo);
    }

    @ApiOperation("根据商户ID查询商户信息")
    @GetMapping("/{id}")
    public Resp<MerchantVo> getMerchantById(@PathVariable("id") Integer id, @RequestParam(required = false) Double latitude, @RequestParam(required = false) Double longitude) {
        MerchantVo merchantVo = merchantService.getMerchantById(id, latitude, longitude);
        return Resp.success(merchantVo);
    }
}